package main

import (
	pb "grpc-test/pb"
	"context"
	"fmt"
	"log"
	"net"
	"google.golang.org/grpc"

    //_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
   // _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
   // _ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
  //  _ "google.golang.org/protobuf/cmd/protoc-gen-go"

)

func main(){
  fmt.Println("grpc-test")
  go func() {
	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 50051))
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	pb.RegisterHelloSVCServer(s, &HelloSVCserver{})
	fmt.Printf("server listening at %v\n", lis.Addr())
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
	select {}
  }()
  select{}
}

type HelloSVCserver struct {
	pb.UnimplementedHelloSVCServer
}


func (p *HelloSVCserver) SayHello(ctx context.Context, r *pb.Request) (*pb.Writer, error) {
        w := &pb.Writer{Msg: "helloxxxx:" + r.GetName()}
	fmt.Println("传入",r)
    return w, nil
}
